--
-- Author: shunguo.chen
-- Date: 2017-12-27 15:02:44
--
-- PvpLevelView pvp赛季等级变化

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.PvpLevelScene

local LEV_UP_STR = L("tips_1150024")
local LEV_DOWN_STR = L("tips_1150025")
local LEV_NEW_STR = L("tips_1150026")
local DATE_STR = L("tips_1150027")
local UNLOCK_STR = L("tips_1150028")
local BOX_STR = L("tips_1150029")

function ClassRef:init()
	self._ui.Button_queding:addClickEventListener(function()
			self:closeView()
		end)
	
end

-- data = PvpSeasonInfo
-- type = 1(升级) 2（降级）3（赛季等级）
function ClassRef:refresh(data, type)
	self._ui.tlt:setString(data:getTitle())
	self._ui["Panel/icon_1/num"]:setString(data.lv)

	if type == 3 then
		self._ui.tips:setString(LEV_NEW_STR)
		self._ui.tips_1:setString(DATE_STR)
		self._ui.tips_2:setString(data:getDateStr())
	else
		self._ui.tips:setString(type == 1 and LEV_UP_STR or LEV_DOWN_STR)
		self._ui.tips_1:setString(UNLOCK_STR)
		self._ui.tips_2:setString(string.format(BOX_STR, data.lv, data:getEndDateStr()))
	end

	display.doTipBgLayout(self._ui.tips, self._ui.tips_img)
end

function ClassRef:refreshSecret(data)
	self._ui.tlt:setString(data.title1)
	if data.title2 then
		self._ui.tips:setString(data.title2)
		
		display.doTipBgLayout(self._ui.tips, self._ui.tips_img)
	else
		self._ui.tips_img:hide()
		self._ui.tips:hide()
	end
	if data.tips1 then
		self._ui.tips_1:setString(data.tips1)
	else
		self._ui.tips_1:hide()
	end
	
	if data.tips2 then
		self._ui.tips_2:setString(data.tips2)
	else
		self._ui.tips_2:hide()
	end

	self._ui["Panel/icon_1/num"]:setString(data.lv)

	-- if data.buttonName then
	-- 	self._ui.Button_queding.name:setString(data.buttonName)
	-- end	
end

function ClassRef:refreshChallenge(seasonId, endTime, lv)
	-- dump(seasonId)
	-- dump(endTime)
	-- dump(lv)

	self._ui.tlt:setString(string.format(L("lua_code_text_142"), seasonId))
	self._ui["Panel/icon_1/num"]:setString(lv)
	self._ui.tips:setString(LEV_UP_STR)

	local str = string.format(L("challengeTips14"), tostring(lv))
	local endDate = os.date("*t", endTime)
	str = str .. string.format(L("challengeTips15"), tostring(endDate.month), tostring(endDate.day), tostring(endDate.hour))
	self._ui.tips_2:setString(str)
end

function ClassRef:refreshEliteMatch(data, type)
	if not data then return end
	local tltStr = data.playId == Enums.TeamTarget.eliteMatchArena and L("EliteMatchTip29") or L("EliteMatchTip43")
	if type == 1 then		
        self._ui.tlt:setString(string.format(tltStr, data.id))
        self._ui.tips:setString(L("EliteMatchTip30"))
        self._ui.tips_1:setString(L("EliteMatchTip32"))
        local endDate = os.date("*t", data.rewardTime)
        local dateStr = string.format(L("EliteMatchTip34"), endDate.month, endDate.day)
        local str
        if data.lv == 0 then
            str = L("EliteMatchTip35")..dateStr
        else
            str = string.format(L("EliteMatchTip33"), data.lv)..dateStr
        end
        self._ui.tips_2:setString(str)
    elseif type == 3 then
        self._ui.tlt:setString(L("EliteMatchTip36"))
        self._ui.tips:setString(string.format(tltStr, data.id))
        self._ui.tips_1:setString(L("EliteMatchTip37"))
        local openTimeStr = os.date("%m.%d", data.startTime)
        local endTimeStr = os.date("%m.%d", data.endTime)
        self._ui.tips_2:setString(openTimeStr.."-"..endTimeStr)
	end
	if data.lv == 0 then
		self._ui["Panel/icon_1/num"]:setVisible(false)
		self._ui["Panel/icon_1/text"]:setVisible(true)
		self._ui["Panel/icon_1/text"]:setString(L("EliteMatchTip31"))
	else
		self._ui["Panel/icon_1/num"]:setVisible(true)
		self._ui["Panel/icon_1/text"]:setVisible(false)
		self._ui["Panel/icon_1/num"]:setString(data.lv)
	end
end

return ClassRef